/*
 * Home.java
 *
 * Created on May 25, 2005, 11:27 AM
 */
package ge.ktapestry.pages;

import ge.ktapestry.propertyselections.Comboes;
import org.apache.tapestry.annotations.InjectObject;
import org.apache.tapestry.event.PageEndRenderListener;
import org.apache.tapestry.event.PageEvent;
import org.apache.tapestry.html.BasePage;

import java.util.ArrayList;
import java.util.List;

public abstract class BasePageWithExceptions extends BasePage implements
        PageEndRenderListener
{
    
    @InjectObject("spring:comboes")
    public abstract Comboes getComboes();
    
    private List<Exception> exceptions;
    private List<Exception> warnings;
    
    public void pageEndRender(PageEvent event)
    {
        if (!event.getRequestCycle().isRewinding())
        {
            if (exceptions != null)
            {
                exceptions.clear();
            }
            else
            {
                exceptions = new ArrayList<Exception>();
            }
            if (warnings != null)
            {
                warnings.clear();
            }
            else
            {
                warnings = new ArrayList<Exception>();
            }
        }
        
    }
    
    public void addException(Exception e)
    {
        getExceptions().add(e);
    }
    public void addWarning(Exception e)
    {
        getWarnings().add(e);
    }
    public List getExceptions()
    {
        if (exceptions == null)
        {
            exceptions = new ArrayList();
        }
        return exceptions;
    }
    
    public List<Exception> getWarnings()
    {
        if (warnings == null)
        {
            warnings = new ArrayList();
        }
        return warnings;
    }
    
}
